package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.PurchaseApplyOrder;
import com.example.demo.service.PurchaseApplyOrderService;
import com.example.demo.mapper.PurchaseApplyOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 18364
* @description 针对表【purchase_apply_order】的数据库操作Service实现
* @createDate 2025-01-08 11:15:37
*/
@Service
public class PurchaseApplyOrderServiceImpl extends ServiceImpl<PurchaseApplyOrderMapper, PurchaseApplyOrder>
    implements PurchaseApplyOrderService{
    @Autowired
    PurchaseApplyOrderMapper purchaseApplyOrderMapper;

    @Override
    public PurchaseApplyOrder selectByInfo(String userId, String trainingId, String identifyCode) {
        QueryWrapper<PurchaseApplyOrder> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }
        if(identifyCode!=null){
            queryWrapper.eq("identifyCode",identifyCode);
        }
        queryWrapper.orderByDesc("orderTime");

        return purchaseApplyOrderMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer delete(String userId, String trainingId) {
        QueryWrapper<PurchaseApplyOrder> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        queryWrapper.eq("trainingId",trainingId);

        return purchaseApplyOrderMapper.delete(queryWrapper);
    }
}




